package com.szh.cloud.api.login.control;

import com.szh.cloud.api.login.entity.SearUserEntity;
import com.szh.cloud.api.login.service.ApiLoginService;
import com.szh.cloud.spring.control.BaseController;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api/login")
public class ApiLoginController extends BaseController {
    @Resource
    private ApiLoginService apiLoginService;
    @RequestMapping("/user")
    public String userLogin(@RequestBody SearUserEntity entity){
        try {
            String userUuid = apiLoginService.userLogin(entity);
            return successCodeJSON("login.user.success",userUuid);
        }catch (UsernameNotFoundException e){
            return failJSON("login.user.fail");
        }
    }
}
